package com.situ.day8;

import org.junit.Test;

public class Homework {
	
	@Test
	public void test1() {
		// 写代码时候要测试一些边界情况，特殊情况
		//String str = "---java Android---";
		//String str = "---java Android";
		String str = "java Android---";
		//String str = "java Android";
		//String str = "------";
		String result = trim(str);
		System.out.println(result);
	}

	private String trim(String str) {
		int startIndex = 0;
		int endIndex = str.length() - 1;
		while ((startIndex <= endIndex) && (str.charAt(startIndex) == '-')) {
			startIndex++;
		}
		while ((startIndex <= endIndex) && (str.charAt(endIndex) == '-')) {
			endIndex--;
		}
		String result = str.substring(startIndex, endIndex + 1);
		return result;
	}
	
	@Test
	public void test2() {
		String str = "I Love Java！";
		char[] array = str.toCharArray();
		for (int i = 0; i < array.length; i++) {
			if (array[i] >= 'A' && array[i] <= 'Z') {
				array[i]  = (char)(array[i] + 32);
			}
		}
		String s = new String(array);
		System.out.println(s);
	}
	
	@Test
	public void test3() {
		String str = "this is my homework! I must finish it!";
		String[] array = str.split(" ");
		System.out.println(array.length);
		
		int count = 0;
		for (String string : array) {
			count++;
		}
		System.out.println(count);
	}
	
	
}
